package cn.com.w.boot_swagger.controller;


import cn.com.w.boot_swagger.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/test")
@Api(tags = "测试controller")
public class TestController {


    /**
     * 获取数据
     * @return
     */
    @GetMapping("/getData")
    @ApiOperation(value = "获取数据")
    public String getData(){
        return "hello word";
    }

    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("/getUser")
    @ApiOperation(value = "获取用户信息", notes = "获取全部用户信息")
    public String getUser(){

        List<User> userList = new ArrayList<>();
        User user1 = new User();
        user1.setId("01");
        user1.setAge(11);
        user1.setName("lucy");
        userList.add(user1);

        User user2 = new User();
        user2.setId("02");
        user2.setAge(12);
        user2.setName("jeck");
        userList.add(user2);

        User user3 = new User();
        user3.setId("03");
        user3.setAge(13);
        user3.setName("tom");
        userList.add(user3);

        System.out.println(userList.toString());
        return userList.toString();
    }

    /**
     * 获取用户信息
     * @return
     */
    @GetMapping(value = "/getUserByName/{name}")
    @ApiOperation(value = "获取用户信息", notes = "根据姓名获取用户信息")
    @ApiImplicitParam(name = "name", value = "用户姓名", required = true, dataType = "String")
    public String getUserByName(@PathVariable(name = "name") String name,
                                @RequestParam(name = "test") String test){
        System.out.println(name);
        return name;
    }

    @PostMapping("/txt")
    @ApiOperation(value = "获取信息")
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "txt1", value = "文本txt1", required = true, dataType = "String"),
            @ApiImplicitParam(name = "txt2", value = "文本txt2", required = true, dataType = "String")}
    )
    public void demo(@RequestParam(name = "txt1") String txt1,
                     @RequestParam(name = "txt2") String txt2) {
        System.out.println("txt1="+txt1);
        System.out.println("txt2="+txt2);
    }
}
